namespace ASPNET.StarterKit.IssueTracker
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class PickQueryField : UserControl
    {
        [AccessedThroughProperty("dropBooleanOperator")]
        private DropDownList _dropBooleanOperator;
        [AccessedThroughProperty("dropComparisonOperator")]
        private DropDownList _dropComparisonOperator;
        [AccessedThroughProperty("dropField")]
        private DropDownList _dropField;
        [AccessedThroughProperty("dropValue")]
        private DropDownList _dropValue;
        [AccessedThroughProperty("txtValue")]
        private TextBox _txtValue;
        private object designerPlaceholderDeclaration;

        public PickQueryField()
        {
            base.Init += new EventHandler(this.Page_Init);
        }

        public void Clear()
        {
            this.dropBooleanOperator.SelectedIndex = -1;
            this.dropField.SelectedIndex = -1;
            this.dropComparisonOperator.SelectedIndex = -1;
            this.dropValue.Items.Clear();
            this.txtValue.Text = string.Empty;
            this.dropValue.Visible = true;
            this.txtValue.Visible = false;
        }

        public void dropFieldSelectedIndexChanged(object s, EventArgs e)
        {
            this.dropValue.Items.Clear();
            string _Vb_t_string_0 = this.dropField.SelectedValue;
            if (StringType.StrCmp(_Vb_t_string_0, "IssuePriorityId", false) == 0)
            {
                this.dropValue.Visible = true;
                this.txtValue.Visible = false;
                this.dropValue.DataSource = Priority.GetPrioritiesByProjectId(this.ProjectId);
                this.dropValue.DataTextField = "Name";
                this.dropValue.DataValueField = "Id";
            }
            else if (StringType.StrCmp(_Vb_t_string_0, "IssueCategoryId", false) == 0)
            {
                this.dropValue.Visible = true;
                this.txtValue.Visible = false;
                this.dropValue.DataSource = new CategoryTree().GetCategoryTreeByProjectId(this.ProjectId);
                this.dropValue.DataTextField = "Name";
                this.dropValue.DataValueField = "Id";
            }
            else if (StringType.StrCmp(_Vb_t_string_0, "IssueStatusId", false) == 0)
            {
                this.dropValue.Visible = true;
                this.txtValue.Visible = false;
                this.dropValue.DataSource = Status.GetStatusByProjectId(this.ProjectId);
                this.dropValue.DataTextField = "Name";
                this.dropValue.DataValueField = "Id";
            }
            else if (StringType.StrCmp(_Vb_t_string_0, "IssueAssignedId", false) == 0)
            {
                this.dropValue.Visible = true;
                this.txtValue.Visible = false;
                this.dropValue.DataSource = ITUser.GetUsersByProjectId(this.ProjectId);
                this.dropValue.DataTextField = "DisplayName";
                this.dropValue.DataValueField = "Id";
            }
            else if (StringType.StrCmp(_Vb_t_string_0, "IssueOwnerId", false) == 0)
            {
                this.dropValue.Visible = true;
                this.txtValue.Visible = false;
                this.dropValue.DataSource = ITUser.GetUsersByProjectId(this.ProjectId);
                this.dropValue.DataTextField = "DisplayName";
                this.dropValue.DataValueField = "Id";
            }
            else if (StringType.StrCmp(_Vb_t_string_0, "IssueCreatorId", false) == 0)
            {
                this.dropValue.Visible = true;
                this.txtValue.Visible = false;
                this.dropValue.DataSource = ITUser.GetUsersByProjectId(this.ProjectId);
                this.dropValue.DataTextField = "DisplayName";
                this.dropValue.DataValueField = "Id";
            }
            else
            {
                this.dropValue.Visible = false;
                this.txtValue.Visible = true;
            }
            this.dropValue.DataBind();
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void txtValue_TextChanged(object sender, EventArgs e)
        {
            if (StringType.StrCmp(this.dropComparisonOperator.SelectedValue, "LIKE", false) == 0)
            {
                this.txtValue.Text = "%" + this.txtValue.Text + "%";
            }
        }

        public string BooleanOperator
        {
            get
            {
                if (this.dropBooleanOperator.Items.FindByValue(this.dropBooleanOperator.SelectedValue) == null)
                {
                    throw new Exception("Invalid Boolean Operator");
                }
                return this.dropBooleanOperator.SelectedValue;
            }
        }

        public string ComparisonOperator
        {
            get
            {
                if (this.dropComparisonOperator.Items.FindByValue(this.dropComparisonOperator.SelectedValue) == null)
                {
                    throw new Exception("Invalid Comparison Operator");
                }
                return this.dropComparisonOperator.SelectedValue;
            }
        }

        public SqlDbType DataType
        {
            get
            {
                string _Vb_t_string_0 = this.dropField.SelectedValue;
                if ((((StringType.StrCmp(_Vb_t_string_0, "IssueId", false) == 0) || (StringType.StrCmp(_Vb_t_string_0, "IssueCategoryId", false) == 0)) || ((StringType.StrCmp(_Vb_t_string_0, "IssuePriorityId", false) == 0) || (StringType.StrCmp(_Vb_t_string_0, "IssueStatusId", false) == 0))) || (((StringType.StrCmp(_Vb_t_string_0, "IssueMilestoneId", false) == 0) || (StringType.StrCmp(_Vb_t_string_0, "IssueAssignedId", false) == 0)) || ((StringType.StrCmp(_Vb_t_string_0, "IssueOwnerId", false) == 0) || (StringType.StrCmp(_Vb_t_string_0, "IssueCreatorId", false) == 0))))
                {
                    return SqlDbType.Int;
                }
                if (StringType.StrCmp(_Vb_t_string_0, "DateCreated", false) == 0)
                {
                    return SqlDbType.DateTime;
                }
                return SqlDbType.NVarChar;
            }
        }

        protected virtual DropDownList dropBooleanOperator
        {
            get
            {
                return this._dropBooleanOperator;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropBooleanOperator != null)
                {
                }
                this._dropBooleanOperator = value;
                if (this._dropBooleanOperator != null)
                {
                }
            }
        }

        protected virtual DropDownList dropComparisonOperator
        {
            get
            {
                return this._dropComparisonOperator;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropComparisonOperator != null)
                {
                }
                this._dropComparisonOperator = value;
                if (this._dropComparisonOperator != null)
                {
                }
            }
        }

        protected virtual DropDownList dropField
        {
            get
            {
                return this._dropField;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropField != null)
                {
                    this._dropField.SelectedIndexChanged -= new EventHandler(this.dropFieldSelectedIndexChanged);
                }
                this._dropField = value;
                if (this._dropField != null)
                {
                    this._dropField.SelectedIndexChanged += new EventHandler(this.dropFieldSelectedIndexChanged);
                }
            }
        }

        protected virtual DropDownList dropValue
        {
            get
            {
                return this._dropValue;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropValue != null)
                {
                }
                this._dropValue = value;
                if (this._dropValue != null)
                {
                }
            }
        }

        public string FieldName
        {
            get
            {
                if (this.dropField.Items.FindByValue(this.dropField.SelectedValue) == null)
                {
                    throw new Exception("Invalid Field Name");
                }
                return this.dropField.SelectedValue;
            }
        }

        public string FieldValue
        {
            get
            {
                string _Vb_t_string_0 = this.dropField.SelectedValue;
                if ((((StringType.StrCmp(_Vb_t_string_0, "IssueCategoryId", false) == 0) || (StringType.StrCmp(_Vb_t_string_0, "IssuePriorityId", false) == 0)) || ((StringType.StrCmp(_Vb_t_string_0, "IssueStatusId", false) == 0) || (StringType.StrCmp(_Vb_t_string_0, "IssueAssignedId", false) == 0))) || ((StringType.StrCmp(_Vb_t_string_0, "IssueOwnerId", false) == 0) || (StringType.StrCmp(_Vb_t_string_0, "IssueCreatorId", false) == 0)))
                {
                    return this.dropValue.SelectedValue;
                }
                return this.txtValue.Text;
            }
        }

        public int ProjectId
        {
            get
            {
                if (this.ViewState["ProjectId"] == null)
                {
                    return 0;
                }
                return IntegerType.FromObject(this.ViewState["ProjectId"]);
            }
            set
            {
                this.ViewState["ProjectId"] = value;
            }
        }

        public ASPNET.StarterKit.IssueTracker.BusinessLogicLayer.QueryClause QueryClause
        {
            get
            {
                if (StringType.StrCmp(this.dropField.SelectedValue, "0", false) == 0)
                {
                    return null;
                }
                return new ASPNET.StarterKit.IssueTracker.BusinessLogicLayer.QueryClause(this.BooleanOperator, this.FieldName, this.ComparisonOperator, this.FieldValue, this.DataType);
            }
        }

        protected virtual TextBox txtValue
        {
            get
            {
                return this._txtValue;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtValue != null)
                {
                    this._txtValue.TextChanged -= new EventHandler(this.txtValue_TextChanged);
                }
                this._txtValue = value;
                if (this._txtValue != null)
                {
                    this._txtValue.TextChanged += new EventHandler(this.txtValue_TextChanged);
                }
            }
        }
    }
}

